package crmdna.custom.isha;

import java.util.Set;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiMethod.HttpMethod;
import com.google.api.server.spi.config.Named;
import com.google.appengine.api.users.User;

import crmdna.common.APIResponse;
import crmdna.common.APIResponse.Status;
import crmdna.common.Utils;
import crmdna.custom.isha.IshaConfig.CustomConfigProp;

@Api(name = "isha")
public class IshaConfigApi {
	
	@ApiMethod(path = "get", httpMethod = HttpMethod.GET)
	public APIResponse get() {
		try {
									
			CustomConfigProp prop = IshaConfig.safeGet();			
			return new APIResponse(Status.SUCCESS, prop);
			
		} catch (Exception ex) {
			return new APIResponse(ex);
		}
	}
	
	@ApiMethod(path = "setSathsangPracticeIds", httpMethod = HttpMethod.POST)
	public APIResponse setSathsangPracticeIds(@Named("sathsang_practice_ids") Set<Long> practiceIds, 
			User user) {
		try {
									
			CustomConfigProp prop = IshaConfig.setSathsangPractices(practiceIds, 
					Utils.getLoginEmail(user));			
			return new APIResponse(Status.SUCCESS, prop);
			
		} catch (Exception ex) {
			return new APIResponse(ex);
		}
	}
}
